{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f930d7f2-532d-4bd7-8c30-134864f51bd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import itertools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c7437e6d-014e-42be-a8cd-11f7f3d4c9a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "natuals = itertools.count(1)\n",
    "ns = itertools.takewhile(lambda x: x <= 10, natuals )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6947a937-73d4-446b-a594-42041435f1ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(ns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b544d255-79a0-473d-aeec-422d649c9346",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A\n",
      "B\n",
      "C\n",
      "X\n",
      "Y\n",
      "Z\n"
     ]
    }
   ],
   "source": [
    "for c in itertools.chain('ABC', 'XYZ'):\n",
    "    print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "83c459d0-038d-4596-89a9-46c33fe1a199",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A ['A', 'A', 'A']\n",
      "B ['B', 'B', 'B']\n",
      "C ['C', 'C', 'C']\n",
      "A ['A', 'A']\n"
     ]
    }
   ],
   "source": [
    "for key, group in itertools.groupby('AAABBBCCCAA'):\n",
    "    print(key, list(group))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06f33694-0f0f-4c47-9e5a-a0a9e3f7704f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
